home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 037a / ccunzip.zip / CRC.PAS < prev    next >
Pascal/Delphi Source File  |  1990-04-05  |  3KB  |  66 lines

  1. { A+,B-,D-,E-,F-,I-,L-,N-,O-,R-,S-,V+}
  2. {$A+,B-,E-,F-,I-,N-,O-,R-,S-,V+}
  3. Unit Crc;
  4. { This unit provides three speed-optimized functions to compute (or continue
  5.   computation of) a Cyclic Redundency Check (CRC).  These routines are
  6.   contributed to the public domain (with the limitations noted by the
  7.   original authors in the TASM sources).  Please see TESTCRC.PAS for
  8.   example usage.
  9.  
  10.   Each function takes three parameters:
  11.  
  12.   InitCRC - The initial CRC value.  This may be the recommended initialization
  13.   value if this is the first or only block to be checked, or this may be
  14.   a previously computed CRC value if this is a continuation.
  15.  
  16.   InBuf - An untyped parameter specifying the beginning of the memory area
  17.   to be checked.
  18.  
  19.   InLen - A word indicating the length of the memory area to be checked.  If
  20.   InLen is zero, the function returns the value of InitCRC.
  21.  
  22.   The function result is the updated CRC.  The input buffer is scanned under
  23.   the limitations of the 8086 segmented architecture, so the result will be
  24.   in error if InLen > 64k - Offset(InBuf).
  25.  
  26.   These conversions were done on 10-29-89 by:
  27.  
  28.   Edwin T. Floyd [76067,747]
  29.   #9 Adams Park Court
  30.   Columbus, GA 31909
  31.   (404) 576-3305 (work)
  32.   (404) 322-0076 (home)
  33. }
  34. Interface
  35.  
  36. Function UpdateCRC16(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  37. { I believe this is the CRC used by the XModem protocol.  The transmitting
  38.   end should initialize with zero, UpdateCRC16 for the block, Continue the
  39.   UpdateCRC16 for two nulls, and append the result (hi order byte first) to
  40.   the transmitted block.  The receiver should initialize with zero and
  41.   UpdateCRC16 for the received block including the two byte CRC.  The
  42.   result will be zero (why?) if there were no transmission errors.  (I have
  43.   not tested this function with an actual XModem implementation, though I
  44.   did verify the behavior just described.  See TESTCRC.PAS.) }
  45.  
  46. Function UpdateCRCArc(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  47. { This function computes the CRC used by SEA's ARC utility.  Initialize
  48.   with zero. }
  49.  
  50. Function UpdateCRC32(InitCRC : LongInt; Var InBuf; InLen : Word) : LongInt;
  51. { This function computes the CRC used by PKZIP and Forsberg's ZModem.
  52.   Initialize with high-values ($FFFFFFFF), and finish by inverting all bits
  53.   (Not). }
  54.  
  55. Implementation
  56. Function UpdateCRC16(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  57. External;
  58. {$L CRC16.OBJ }
  59. Function UpdateCRCArc(InitCRC : Word; Var InBuf; InLen : Word) : Word;
  60. External;
  61. {$L CRCARC.OBJ }
  62. Function UpdateCRC32(InitCRC : LongInt; Var InBuf; InLen : Word) : LongInt;
  63. External;
  64. {$L CRC32.OBJ }
  65. End.
  66.